<?php

namespace Admin\Frontend\Controllers;

use Helpers\Cache;
use Helpers\Tool;
use Helpers\Main;
use Helpers\UserPower;
use Helpers\Template;
use Helpers\Assets;
use Admin\Models\sys\XhsysTree;
use Admin\Models\sys\XhsysFunction;
use Admin\Models\sys\XhsysPower;
use Admin\Models\sys\XhsysEnum;
use Services\Sys\Enum;
use Services\Sys\Nav;
use Services\Sys\Power;

class SysController extends ControllerBase
{

    /**
     * 添加导航页面
     *
     * create by ck 20160229
     */
    public function navAddAction()
    {
        $this->view->pick('sys/navAdd');
//        Assets::importMainJs('assets/jquery/jquery.form.js');
        Assets::importJs('js/sys/navAdd.js');
        $this->view->setVar('navTree', Nav::createNavTree());         //生成导航数组后组成导航结构树
    }

    /**
     * 添加导航
     * 无父节点：截取出 节点编号 前两位最大的数并加1
     * 有父节点：获取 节点编号 如编号等于父节点编号，则追加01，否则直接+1
     * 如有url，则在Function表中也新建记录
     *
     * create by ck 20160301
     * modify by ck 20160617    优化
     * modify by ck 20160822    结构更改
     * modify by ck 20190107    重构
     */
    public function addNavNodeAction()
    {
        $nodeName = $this->request->getPost('sNodeName', 'string');
        if (!$nodeName) {
            return $this->sendErrorResponse(400, '缺少节点名称');
        }
        try {
            Nav::addNav($this->request->getPost());
            return $this->sendJsonResponse([
                'tree' => Nav::createNavTree([], null, null, false)
            ]);
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $dbRollback = false;
//        $this->db->begin();
//        $tree = XhsysTree::createRecord($this->request->getPost());
//        if (!$tree->insertData()) {
//            $dbRollback = true;
//            goto dealTrans;
//        }
//        Main::createCommitLog('sys', 'Nav', 'add', $tree, $tree->iNodeId, '系统树');
//        if ($this->request->getPost('FunctionUrl') != '') {
//            $function          = XhsysFunction::createRecord($this->request->getPost());
//            $function->iNodeId = $tree->iNodeId;
//            if (!$function->insertData()) {
//                $dbRollback = true;
//                goto dealTrans;
//            }
//            Main::createCommitLog('sys', 'Nav', 'add', $function, $function->iFunctionId, '导航');
//        }
//        dealTrans:
//        if ($dbRollback) {
//            $this->db->rollback();
//            die('fail');
//        }
//        $this->db->commit();
//        Cache::flush();
//        echo XhsysTree::createNavTree([], null, null, false);
    }

    /**
     * 修改导航页面
     *
     * create by ck 20160301
     */
    public function navEditAction()
    {
        $this->view->pick('sys/navEdit');
//        Assets::importMainJs('assets/jquery/jquery.form.js');
        Assets::importJs('js/sys/navEdit.js');
        $this->view->setVar('navTree', Nav::createNavTree([], 'fa-times'));
    }

    /**
     * 修改导航
     * 如果输入了URL，则查找Function表中记录，找到则修改，未找到则新建
     * 如果未输入URL，则查找Function表中记录，找到则删除，未找到不操作
     *
     * create by ck 20160301
     * modify by ck 20160617    优化
     * modify by ck 20160822    结构更改
     * modify by ck 20161019    添加url时带上nodeId
     * modify by ck 20161116    优化
     * modify by ck 20190107    重构
     */
    public function editNavNodeAction()
    {
        $nodeId   = $this->request->getPost('iNodeId', 'int');
        $nodeName = $this->request->getPost('sNodeName', 'string');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少节点id');
        }
        if (!$nodeName) {
            return $this->sendErrorResponse(400, '缺少节点名称');
        }
        try {
            Nav::editNav($nodeId, $nodeName, $this->request->getPost());
            return $this->sendJsonResponse([
                'tree' => Nav::createNavTree([], 'fa-times', null, false)
            ]);
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $nodeId = $this->request->getPost('NodeID', 'int');
//        $dbRollback = false;
//        $this->db->begin();
//        $node = XhsysTree::createRecord($this->request->getPost(), $nodeId);
//        if(!$node->updateData()) {
//            $dbRollback = true;
//            goto dealTrans;
//        }
//        Main::createCommitLog('sys', 'Nav', 'edit', $node, $node->iNodeId, '系统树');
//        $oldFunction = XhsysFunction::findFirst("iNodeId = {$node->iNodeId} AND bDelete = 0");
//        if($this->request->getPost('FunctionUrl') != ''){
//            $function = XhsysFunction::createRecord($this->request->getPost(), $oldFunction);
//            $function->iNodeId = $node->iNodeId;
//            if(!($oldFunction ? $function->updateData() : $function->insertData())) {
//                $dbRollback = true;
//                goto dealTrans;
//            }
//            Main::createCommitLog('sys', 'Nav', 'edit', $function, $function->iFunctionId, '导航');
//        }
//        elseif($oldFunction){
//            if(!$oldFunction->delete()) {
//                $dbRollback = true;
//                goto dealTrans;
//            }
//            Main::createCommitLog('sys', 'Nav', 'del', $oldFunction, $oldFunction->iFunctionId, '导航');
//        }
//        dealTrans:
//        if($dbRollback) {
//            $this->db->rollback();
//        }
//        $this->db->commit();
//        Cache::flush();
//        echo XhsysTree::createNavTree([], 'fa-times', null, false);
    }

    /**
     * 读取节点信息给js文件，以json格式返回
     *
     * create by ck 20160301
     * modify by ck 20160617
     * modify by ck 20160822    结构更改
     * modify by ck 20190107    重构
     */
    public function getNodeInfoAction()
    {
        $nodeId = $this->request->getPost('nodeId', 'string');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少节点id');
        }
        try {
            return $this->sendJsonResponse(Nav::getNavInfo($nodeId));
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $nodeId = $this->request->getPost('iNodeId');
//        echo json_encode(XhsysTree::getNodeInfoById($nodeId));
    }

    /**
     * 删除导航，如果该节点在Function表中有记录则同时删除
     *
     * create by ck 20160301
     * modify by ck 20160617
     * modify by ck 20160617
     * modify by ck 20160822    结构更改
     * modify by ck 20190107    重构
     */
    public function delNavNodeAction()
    {
        $nodeId = $this->request->getPost('nodeId', 'int');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少节点id');
        }
        try {
            Nav::delNavNode($nodeId);
            return $this->sendJsonResponse([
                'tree' => Nav::createNavTree([], 'fa-times', null, false)
            ]);
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $nodeId = $this->request->getPost('iNodeId');
//        XhsysTree::findFirst($nodeId)->delete();
//        echo XhsysTree::createNavTree([], 'fa-times', null, false);
    }

    /**
     * 添加权限页面
     *
     * create by ck 20160310
     * modify by ck 20160822    结构更改
     */
    public function powerAddAction()
    {
        $this->view->pick('sys/powerAdd');
//        Assets::importMainJs('assets/jquery/jquery.form.js');
        Assets::importJs('js/sys/powerAdd.js');
        return $this->view->setVar('powerTree', Nav::createNavTree());
    }

    /**
     * 根据节点id，获取节点编号，如已有权限数据，则获取
     *
     * create by ck 20160310
     * modify by ck 20160617    优化
     * modify by ck 20160823    结构更改
     * modify by ck 20180810    重构
     * modify by ck 20190108    重构
     */
    public function readPowerInfoAction()
    {
        $nodeId  = $this->request->getPost('id', 'int');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少id');
        }
        try {
            return $this->sendJsonResponse(Power::getNodePowerInfo($nodeId));
//            $node = XhsysTree::findFirst($nodeId);
//            if (!$node) {
//                throw new \Exception('无节点信息');
//            }
//            $data = [
//                'powerNodeId'   => $node->iNodeId,
//                'powerNodeName' => $node->sNodeName
//            ];
//            $powers = XhsysPower::find([
//                'columns'    => 'iPowerId as powerId,sPowerTag as powerTag,sPowerName as powerName,sExtraUrl as extraUrl,bPowerMain',
//                'conditions' => 'iNodeId = :nodeId:',
//                'bind'       => ['nodeId' => $nodeId]
//            ])->toArray();
//            if ($powers) {
//                foreach ($powers as $power) {
//                    if ($power['bPowerMain']) {
////                        $data['mainPowerId']   = $power['powerId'];
//                        $data['mainPowerTag']  = $power['powerTag'];
//                        $data['mainPowerName'] = $power['powerName'];
//                        $data['mainExtraUrl']  = $power['extraUrl'];
//                    } else {
//                        $data['extra'][] = [
////                            'powerId'   => $power['powerId'],
//                            'powerTag'  => $power['powerTag'],
//                            'powerName' => $power['powerName'],
//                        ];
//                    }
//                }
//
//            }
////            $power = XhsysPower::findFirst("iNodeId = {$nodeId}");
////            if ($power) {
////                $data['iPowerId']    = $power->iPowerId;
////                $data['sPowerTag']   = $power->sPowerTag;
////                $data['sPowerName']  = $power->sPowerName;
////                $data['sExtraUrl']   = $power->sExtraUrl;
////            }
//            return $this->sendJsonResponse($data);
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, $e->getMessage());
        }
    }

    /**
     * 新增权限,传入id则不操作，如传入编号则新增权限及增删改附加权限，否则只增加一个其他权限
     *
     * create by ck 20160310
     * modify by ck 20160617
     * modify by ck 20161013
     * modify by ck 20170406    扩展权限可修改
     */
//    public function modifyPowerDataAction()
//    {
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $realData   = Main::getRealData($this->request->getPost());
//        $otherPower = !empty($realData['OtherPower']) ? true : false;
//        $check      = XhsysPower::findFirst("sPowerTag = '{$realData['sPowerTag']}'");
//        isset($realData['ExtraPower']) or $realData['ExtraPower'] = 0;
//        if($realData['ExtraPower']){
//            $check->sExtraUrl = $realData['sExtraUrl'];
//            $check->save() or die('扩展权限添加失败！');
//            Main::createCommitLog('sys', 'Power', 'edit', $realData, $check->iNodeId, '添加扩展权限');
//        }
//        else{
//            !$check or die('（109109001）权限标识已存在');
//            $dbRollback = false;
//            $this->db->begin();
//            if(!XhsysPower::createRecord($realData, !$otherPower)) {
//                $dbRollback = true;
//                goto dealTrans;
//            }
//            if(!$otherPower) {
//                $extra = array('_Add' => '增加', '_Edit' => '修改', '_Del' => '删除');
//                foreach($extra as $tag => $name){
//                    $info  = $realData;
//                    $info['sPowerTag'] .= $tag;
//                    $info['sPowerName'] = $name;
//                    if(!XhsysPower::createRecord($info)) {
//                        $dbRollback = true;
//                        goto dealTrans;
//                    }
//                }
//            }
//            dealTrans:
//            if($dbRollback) {
//                $this->db->rollback();
//                die('（109109002）添加权限失败！');
//            }
//            Cache::flush();                       //刷新缓存
//            Main::createCommitLog('sys', 'Power', 'add', $realData);
//            $this->db->commit();
//        }
//        echo '添加权限成功';
//    }

    /**
     * 保存权限
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by ck 20180812
     * modify by ck 20190108    重构
     */
    public function savePowerAction()
    {
        $nodeId        = $this->request->getPost('powerNodeId', 'int');
        $mainPowerTag  = $this->request->getPost('mainPowerTag', 'string');
        $mainPowerName = $this->request->getPost('mainPowerName', 'string', '查看');
        $mainExtraUrl  = $this->request->getPost('mainExtraUrl', 'string');
        $powerTags     = $this->request->getPost('powerTag', 'string');
        $powerNames    = $this->request->getPost('powerName', 'string');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少节点id');
        }
        if (!$mainPowerTag) {
            return $this->sendErrorResponse(400, '主权限不能为空');
        }
        try {
            $mainPower = [
                'tag' => $mainPowerTag,
                'name' => $mainPowerName,
                'extraUrl' => $mainExtraUrl
            ];
            $extraPower = array_combine($powerTags, $powerNames);
            Power::saveNodePower($nodeId, $mainPower, $extraPower);
            return $this->sendSuccessResponse('保存成功');
//            $this->db->begin();
//            //删除原权限
//            XhsysPower::find([
//                'conditions' => 'iNodeId = :nodeId:',
//                'bind'       => ['nodeId' => $nodeId]
//            ])->delete();
//
//            //检查是否重复
//            $existPower = XhsysPower::count([
//                'columns'    => 'sPowerTag',
//                'conditions' => 'sPowerTag IN ({powerTags:array})',
//                'bind'       => ['powerTags' => array_merge([$mainPowerTag], array_filter($powerTags))]
//            ]);
//            if ($existPower) {
//                throw new \Exception('权限已存在');
//            }
//
//            //处理主权限
//            $power = new XhsysPower(['iNodeId' => $nodeId, 'bPowerMain' => 1]);
//            $power->sPowerTag  = $mainPowerTag;
//            $power->sPowerName = $mainPowerName;
//            $power->sExtraUrl  = $mainExtraUrl;
//            if (!$power->save()) {
//                throw new \Exception($power->getError());
//            }
//
//            //处理其他权限
//            for ($i = 0; $i < count($powerTags); $i++) {
//                if (!$powerTags[$i] || !$powerNames[$i]) {
//                    continue;
//                }
//                $power = new XhsysPower(['iNodeId' => $nodeId]);
//                $power->sPowerTag  = $powerTags[$i];
//                $power->sPowerName = $powerNames[$i];
//                if (!$power->save()) {
//                    throw new \Exception($power->getError());
//                }
//            }
//            $this->db->commit();
//            return $this->sendSuccessResponse('保存成功');
        } catch (\Exception $e) {
            $this->db->rollback();
            return $this->sendErrorResponse(500, '保存失败', $e->getMessage());
        }
    }

    /**
     * 权限列表
     *
     * create by ck 20160310
     * modify by ck 20160617 优化
     */
//    public function powerListAction()
//    {
//        $this->view->pick('sys/powerList');
//        Assets::easyUI('js/sys/powerList.js');
//        Template::exists('XHSys_Power', 'list') or die(Main::showMessageModal('列表配置文件不存在，请先创建！', 109109003));
//        $listSearchArr[] = ['type' => 'text', 'id' => 'list_search', 'label' => '搜索： '];
//        $this->view->setVars([
//            'List'  => Template::createList('List', 'XHSys_Power', [
//                'checkbox'      => false,
//                'searchToolbar' => Template::createSearchToolBar($listSearchArr)
//            ])
//        ]);
//    }

    /**
     * 根据页码及每页行数获取数据并以json格式返回
     *
     * create by ck 2016310
     * modify by ck 20160617    优化
     * modify by ck 20161020    添加搜索条件
     */
//    public function getPowerDataAction()
//    {
//        $this->view->disable();
//        $parameters['conditions'] = null;
//        Main::runSearchVagueConditions($parameters['conditions'], ['sPowerTag', 'sPowerName']);
//        echo Main::runModelPaginator('\\Admin\\Models\\sys\\XhsysPower', $parameters);
//    }

    /**
     * 添加枚举页面
     *
     * create by ck 20160315
     * modify by ck 20160615    优化
     * modify by ck 20161014    js集合
     */
    public function enumAddAction()
    {
        $this->view->pick('sys/enumAdd');
//        Assets::importMainJs('assets/jquery/jquery.form.js');
        Assets::importJs('js/sys/enumAdd.js');
    }

    /**
     * 在tree表中添加节点，类型为枚举，并返回添加节点的编号
     *
     * create by ck 20160315
     * modify by ck 20160615    优化
     * modify by ck 20160822    结构更改
     * modify by ck 20190108    重构
     */
    public function addEnumNodeAction()
    {
        $enumName = $this->request->getPost('enumName', 'string');
        if (!$enumName) {
            return $this->sendErrorResponse(400, '缺少枚举名称');
        }
        try {
            $nodeId = Enum::addEnum($enumName);
            return $this->sendSuccessResponse($nodeId);
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $nodeName = $this->request->getPost('NodeName', 'string');
//        $tree     = XhsysTree::findFirst("sNodeName = '{$nodeName}' AND iNodeType = 2 AND bDelete = 0");
//        !$tree or die('error');
//        $node = XhsysTree::createRecord($this->request->getPost());
//        $node->insertData() or die(Main::showMessageModal('新增失败！', 109109004));
//        Main::createCommitLog('sys', 'Enum', 'add', $node, $node->iNodeId, '枚举节点');
//        echo $node->iNodeId;
    }

    /**
     * 根据NodeCode增加枚举项
     *
     * create by ck 20160315
     * modify by ck 20160615    优化
     * modify by ck 20160822    结构变化
     * modify by ck 20190108    重构
     */
    public function addEnumValueAction()
    {
        $nodeId = $this->request->getPost('nodeId', 'int');
        $name = $this->request->getPost('name', 'string');
        $value = $this->request->getPost('value', 'string');
        if (!$nodeId || !$name || !$value) {
            return $this->sendErrorResponse(400, '缺少必要参数');
        }
        try {
            Enum::addEnumValue($nodeId, $name, $value);
            return $this->sendSuccessResponse("成功添加枚举项。名称：{$name}，值：{$value}");
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $nodeId = $this->request->getQuery('iNodeId', 'int');
//        $nodeId or die;
//        $realData = Main::getRealData($this->request->getPost());
//        $realData['iNodeId'] = $nodeId;
//        $enum = XhsysEnum::createRecord($realData);
//        $enum->insertData() or die(Main::showMessageModal('新增失败！', 109109005));
//        Main::createCommitLog('sys', 'Enum', 'add', $enum, $enum->iEnumId, '枚举项');
//        echo "成功添加枚举项。名称：{$enum->sEnumName}，值：{$enum->sEnumValue}";
    }

    /**
     * 枚举列表页面
     *
     * create by ck 20160315
     * modify by ck 20160615    优化
     * modify by ck 20160617    优化
     * modify by ck 20160822    结构更改
     * modify by ck 20161014    js集合
     */
    public function enumListAction()
    {
        $this->view->pick('sys/enumList');
        Assets::easyUI('js/sys/enumList.js');
        $listButtonArr = $formButtonArr = array();
        $listButtonArr[] = array('id'=>'bt_list_add', 'text'=>'增加', 'plain'=>'true', 'icon'=>'fa-plus');
        $listButtonArr[] = array('id'=>'bt_list_del', 'text'=>'删除', 'plain'=>'true', 'icon'=>'fa-trash');
        $formButtonArr[] = array('id'=>'bt_form_add', 'text'=>'增加', 'class'=>'disabled');
        $formButtonArr[] = array('id'=>'bt_form_edit', 'text'=>'修改', 'class'=>'disabled');
        $formButtonArr[] = array('id'=>'bt_form_back', 'text'=>'返回');
        $formButtonArr[] = array('id'=>'bt_form_reset', 'text'=>'重置');
        return $this->view->setVars([
            'List'       => Template::createList('list', 'XHSys_Enum', [
                'buttonToolbar' => Template::createButtonToolBar($listButtonArr)
            ]),
            'Form'       => Template::createForm('XHSys_Enum'),
            'FormButton' => Template::createButtonToolBar($formButtonArr)
        ]);
    }

    /**
     * 根据页码及每页行数获取数据并以json格式返回
     *
     * create by ck 20160315
     * modify by ck 20160822    结构更改
     * modify by ck 20161014    查询构建优化
     * modify by ck 20170224    命名空间更改
     * modify by ck 20190108    重构
     */
    public function getEnumListAction()
    {
        return $this->sendJsonResponse(Enum::getEnumList());
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $builder = $this->modelsManager->createBuilder()
//            ->from(['enum' => '\\Admin\\Models\\sys\\XhsysEnum'])
//            ->columns(['enum.iNodeId', 'enum.iEnumId', 'enum.sEnumName', 'enum.sEnumValue', 'tree.sNodeName'])
//            ->leftJoin('\\Admin\\Models\\sys\\XhsysTree', 'enum.iNodeId = tree.iNodeId', 'tree')
//            ->where('enum.bDelete = 0 AND tree.bDelete = 0')
//            ->orderBy('enum.iNodeId,enum.iEnumId');
//        echo Main::runBuilderPaginator($builder);
    }

    /**
     * 根据传入id及类型从数据库获取数据并添加到表单中
     *
     * create by ck 20160316
     * modify by ck 20160822    结构更改
     */
//    public function createEnumFormWithDataAction(){
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $id   = $this->request->getPost('id', 'int');
//        $type = $this->request->getPost('type', 'string');
//        $id && $type or die(Main::showMessageModal('参数不完整！', 109109007));
//        if($type == 'add'){
//            $enum = XhsysEnum::findFirst($id);
//            $obj  = XhsysTree::findFirst(array(
//                'columns'    => 'iNodeId,sNodeName',
//                'conditions' => "iNodeId = {$enum->iNodeId}"
//            ))->toArray();
//        }
//        else{
//            $enum = XhsysEnum::findFirst(array(
//                'columns'    => 'iEnumId,iNodeId,sEnumName,sEnumValue',
//                'conditions' => "iEnumId = {$id}",
//            ))->toArray();
//            $tree = XhsysTree::findFirst(array(
//                'columns'    => 'sNodeName',
//                'conditions' => "iNodeId = {$enum['iNodeId']}",
//
//            ))->toArray();
//            $obj = array_merge($enum, $tree);
//        }
//        echo Template::createFormWithData('XHSys_Enum', $obj);
//    }

    /**
     * 插入，修改数据
     *
     * create by ck 20160316
     * modify by ck 20160617    优化
     * modify by ck 20160822    结构更改
     * modify by ck 20161014    结构简化
     * modify by ck 20190108    重构
     */
    public function modifyEnumAction()
    {
        $nodeId = $this->request->getPost('iNodeId', 'int');
        $enumId = $this->request->getPost('iEnumId', 'int');
        $name   = $this->request->getPost('sEnumName', 'string');
        $value  = $this->request->getPost('sEnumValue', 'string');
        if (!$nodeId) {
            return $this->sendErrorResponse(400, '缺少节点id');
        }
        try {
            if ($enumId) {
                Enum::modifyEnumValue($enumId, $name, $value);
            } else {
                Enum::addEnumValue($nodeId, $name, $value);
            }
            return $this->sendSuccessResponse('操作成功');
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $this->view->disable();
//        $this->request->isPost() or die;
//        $realData = Main::getRealData($this->request->getPost());
//        $enum = XhsysEnum::createRecord($realData);
//        $result = $enum->iEnumId ? $enum->updateData() : $enum->insertData();
//        $result or die(Main::showMessageModal('操作失败！', 109109008));
//        Main::createCommitLog('sys', 'Enum', $enum->iEnumId ? 'edit' : 'add', $enum, $enum->iEnumId, '枚举项');
    }

    /**
     * 删除枚举
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by dale 20171221
     * modify by ck 20190108    重构
     */
    public function delEnumAction()
    {
        $ids = $this->request->getPost('ids', 'int');
        if (!$ids) {
            return $this->sendErrorResponse(400, '缺少参数');
        }
        try {
            Enum::delEnumValue($ids);
            return $this->sendSuccessResponse('删除成功');
        } catch (\Exception $e) {
            return $this->sendErrorResponse(500, '系统异常', $e->getMessage());
        }
//        $res = XhsysEnum::deleteRecord('iEnumId', $ids);
//        if (!$res) {
//            return $this->sendErrorResponse(500, '删除失败');
//        }
//        return $this->sendSuccessResponse('删除成功');
    }
}

